# -*- mode: sh -*-

# if we're in st TERM, assume we're in xst and set to esc code, else default.
# dirty, but AFAIK there is no way to detect if esc code yields nothing visible from
# the shell (as it will see the escape code only either way).
case $TERM in
    st*)
        # don't do so in tmux, ssh access won't understand.
        [ -z "$TMUX" ] && \
            _prompt=$'\e[z' || \
            _prompt='$'
        ;;
    *)
        _prompt='$'
        ;;
esac

prompt() {
    _ERR=$?
    [ $(jobs | wc -l) -ne 0 ] && _prompt="$_prompt$_prompt"
    [ $_ERR -ne 0 ] && _prompt="\e[7m$_prompt\e[0m" # invert
    printf "%b%s" "$_prompt "
}

PS1='$(prompt)'
